{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7075193c",
   "metadata": {},
   "outputs": [],
   "source": [
    "——————\n",
    "* 日期：2022-10-19\n",
    "* 课程：python"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd13899e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 本周学习目标\n",
    ">1.列表的方法\n",
    ">2. while循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b7756e34",
   "metadata": {},
   "outputs": [],
   "source": [
    "list1 = ['Google', 'Runoob', 'Taobao', 'Baidu']\n",
    "list1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fd8fafb9",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 1,1列表的增加\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5278c06",
   "metadata": {},
   "outputs": [],
   "source": [
    "list1.append(\"lihua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25bd71b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "list1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "352721c8",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 1.2 列表的插入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "70c0fc60",
   "metadata": {},
   "outputs": [],
   "source": [
    "### insert\n",
    "list1 = ['Google', 'Runoob', 'Taobao']\n",
    "list1.insert(1, 'Baidu')\n",
    "print ('列表插入元素后为 : ', list1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5504be16",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 1.3 列表的删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b1bbcab0",
   "metadata": {},
   "outputs": [],
   "source": [
    "### remove\n",
    "list1 = ['Google', 'Runoob', 'Taobao', 'Baidu']\n",
    "list1.remove('Taobao')\n",
    "print (\"列表现在为 : \", list1)\n",
    "list1.remove('Baidu')\n",
    "print (\"列表现在为 : \", list1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2c272d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "* 正确的删除\n",
    "> 查询值是否存在列表当中 in\n",
    "> 对存在的value进行删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ce1a0a33",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"wang\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "acb1de08",
   "metadata": {},
   "outputs": [],
   "source": [
    "if \"wang\" in list1:\n",
    "    list1.remove(\"wang\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5078dd5a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践： 删除系统： 1.如果输入的值存在，则删除 2.如果输入的结果不存在，提示用户查询无结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b35585dc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2a5fbbf2",
   "metadata": {},
   "outputs": [],
   "source": [
    "list1 = ['Google', 'Runoob', 'Taobao', 'Baidu']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "93e3d60f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Google', 'Runoob', 'Taobao', 'Baidu']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "1ecaf024",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入需要删除的内容:Taobao\n",
      "删除成功！\n",
      "['Google', 'Baidu']\n"
     ]
    }
   ],
   "source": [
    "user_input_list1 = input(\"输入需要删除的内容:\")\n",
    "if user_input_list1 in list1:\n",
    "    list1.remove(user_input_list1)\n",
    "    print(\"删除成功！\")\n",
    "else:\n",
    "    print(\"您输入的结果不存在，请查正后再输入\")\n",
    "print(list1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "523fdb82",
   "metadata": {},
   "outputs": [],
   "source": [
    "================================================================================"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a06f9dd5",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 列表删除的第二种方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c6ae9bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "list2 = ['Google', 'Runoob', 'Taobao']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "45c9b650",
   "metadata": {},
   "outputs": [],
   "source": [
    "查询列表长度 len()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "f7a55d3e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入删除的索引值：2\n"
     ]
    }
   ],
   "source": [
    "list2 = ['Google', 'Runoob', 'Taobao']\n",
    "pop_index = int(input(\"输入删除的索引值：\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "748fd5b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您输入的值不在index的范围内\n"
     ]
    }
   ],
   "source": [
    "if pop_index<len(list2):\n",
    "    list2.pop(pop_index)\n",
    "else:\n",
    "    print(\"您输入的值不在index的范围内\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "5d6689af",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 列表的修改\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "cad817a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "list2[0] = \"fjakl\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "a2ba9449",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['fjakl', 'Runoob']"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "35af9997",
   "metadata": {},
   "outputs": [],
   "source": [
    "======================================================================"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e4e19041",
   "metadata": {},
   "outputs": [],
   "source": [
    "*sort() 排序，一般数值操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "e95007df",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生 = [230,250,245,255,260,270]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "29769c3f",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "2df2b1a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[230, 245, 250, 255, 260, 270]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "立定跳远_男生"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "a2d6d4a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生.sort(reverse=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "7fa332ee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[270, 260, 255, 250, 245, 230]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "立定跳远_男生"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c2c263eb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
